home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir28 / papc20.zip / PAPC.HLP < prev    next >
Text File  |  1994-04-05  |  40KB  |  1,133 lines

  1. *****************************************************************************
  2. *                                                                           *
  3. *       Programmable Arbitrary Precision RPN Calculator                     *
  4. *       Copyright (C) 1993, 1994 by S. Jason Olasky, all rights reserved.   *
  5. *                                                                           *
  6. *****************************************************************************
  7.  
  8. Programmable Arbitrary Precision RPN Calculator, v. 2.0 for DOS
  9.  
  10. written by:
  11.  
  12.     S. Jason Olasky
  13.     874 New Mark Esplanade
  14.     Rockville, MD 20850
  15.     301-294-9419
  16.     Compuserve [70471,2501]
  17.  
  18. Features of this calculator:
  19.  
  20.    * Arbitrary precision, up to 1075 digits
  21.    * Arbitrary number of decimal places with rounding
  22.    * Fully editable input
  23.    * Commas allowed in input
  24.    * Recall of up to ten previous input lines
  25.    * Error checking
  26.    * Virtual stack and memory register array
  27.    * Pressing F1 spawns list to read this help file
  28.    * Pressing F2 spawns an editor of your choice
  29.    * Standard financial functions
  30.    * Date functions based on Julian Day Number
  31.    * Hexadecimal, Octal, and Binary conversions
  32.    * Programmable (similar to HP-41)
  33.  
  34. The following is a list of the operations currently supported by PAPC:
  35.  
  36.            OPCODE        Function
  37.            ------        --------
  38.  
  39.             "+",          Add,
  40.             "-",          Subtract,
  41.             "*",          Multiply,
  42.             "/",          Divide,
  43.             "^",          Power,
  44.             "%",          PerCent,
  45.             "\",          Reciprocal,
  46.  
  47.             "ABS",        AbsoluteValue,
  48.             "ACOS",       ArcCosine,
  49.             "ASIN",       ArcSine,
  50.             "ATAN",       ArcTangent,
  51.  
  52.             "BE",         BE,
  53.             "BIN",        ShowBinary,
  54.  
  55.             "CD",         CD,
  56.             "CF",         CF,
  57.             "CHS",        ChangeSign,
  58.             "CLST",       ClearStack,
  59.             "CLRF",       ClearFinReg,
  60.             "CLRG",       ClearRegisters,
  61.             "CLS",        ClearScreen,
  62.             "COS",        Cosine,
  63.  
  64.             "DATE",       Date,
  65.             "DOW",        DayOfTheWeek,
  66.             "DROP",       Drop,
  67.             "DUP",        Dup,
  68.  
  69.             "E",          e,
  70.             "EXIT"        Quit
  71.             "EXP10",      Exp10,
  72.             "EXPE",       ExpE,
  73.  
  74.             "FACT",       Factorial,
  75.             "FIX",        FixNotation,
  76.             "FRACT",      FractionPart,
  77.             "FV",         FV,
  78.  
  79.             "HEX",        ShowHex,
  80.             "HMS",        HMS,
  81.             "HRS",        HRS,
  82.  
  83.             "I",          I,
  84.             "IND",        SetIndirectFlag,
  85.             "INT",        IntegerPart,
  86.  
  87.             "JDN",        JDN,
  88.  
  89.             "LOG",        Log,
  90.             "LN",         Ln,
  91.  
  92.             "MOD",        Modulo,
  93.  
  94.             "N",          N,
  95.  
  96.             "OCT",        ShowOctal
  97.             "OVER",       Over,
  98.  
  99.             "PF",         PF,
  100.             "PI",         Pi,
  101.             "PICK",       Pick,
  102.             "PMT",        PMT,
  103.             "PREC",       SetPrecision,
  104.             "PV",         PV,
  105.  
  106.             "QUIT"        Quit
  107.  
  108.             "RCL",        Recall,
  109.             "RCLM",       RecallMultiple,
  110.             "ROLL",       Roll,
  111.             "ROT",        Rot,
  112.  
  113.             "SCI",        SciNotation,
  114.             "SHOWS",      ShowStack,
  115.             "SIN",        Sine,
  116.             "SQR",        Square,
  117.             "SQRT",       SquareRoot,
  118.             "STO",        Store,
  119.             "STOM",       StoreMultiple,
  120.             "SWAP",       Swap,
  121.  
  122.             "TAN",        Tangent,
  123.  
  124.             "VIEW",       ViewReg,
  125.  
  126.             "XCH",        Exchange
  127.  
  128. General Notes
  129. -------------
  130.  
  131. This is a programmable arbitrary precision RPN (reverse polish notation) line
  132. oriented calculator, which includes financial and date functions in addition
  133. to many standard mathematical functions. As I eventually intend to rewrite and
  134. expand this as a Windows application, the user interface was left fairly
  135. primitive, however the current version should run without any problems in a
  136. DOS window. The extended precision math routines are derived from the Bigcalc
  137. extended precision calculator written by Judson D. McClendon.
  138.  
  139. Virtual arrays are used for the stack and memory registers, so there are no
  140. effective limits on the stack size or number of registers. One register
  141. requires slightly more than 1K, so 1.1MB of disk storage will suffice for 1000
  142. registers. The help function requires Buerg's list.com or other program named
  143. list (.com or .exe) to be in your path. Pressing F1 will spawn list to read
  144. this file, which should be in your current directory, or in the directory
  145. named in the PAPC environment variable.
  146.  
  147. This calculator is programmable, using operators somewhat similar to those used
  148. in the HP-41. Pressing F2 can be used to load an editor, as defined by the EDIT
  149. environment variable.
  150.  
  151. All opcodes are case insensitive. One character opcodes, i.e. +, -, *, /,
  152. \, ^ , % do not need to be separated from the previous number or operator by
  153. a space, but all other opcodes do. Thus 123 3 4+^ is valid but 123 3STO will be
  154. flagged as an error. Numbers may be preceded by a + or - sign.
  155.  
  156. The stack is based on the FORTH model rather than the HP calculator model;
  157. that is, the stack expands and contracts as numbers are entered or result
  158. from operations upon numbers already on the stack. As a general rule, any
  159. operation upon one or more numbers removes those numbers from the stack. To
  160. re-utilize a number, additional copies may be added to the stack with stack
  161. operations or the number may be stored in a register. Certain stack operations
  162. refer to a number on the stack relative to the top of the stack. Thus the
  163. topmost number is stack[0], the nextmost stack[1], etc. See the pick and roll
  164. operations, and shows. The prompt shows the number of elements on the stack.
  165. Thus the prompt 2> indicates that there are two numbers on the stack. If the
  166. stack is non-empty, the number on top of the stack will be displayed before
  167. the prompt. The stack is implemented as a virtual array, so there are no
  168. limits on the number of elements on the stack. Some stack operations allow
  169. indirect references, that is the number on the stack is used as an index to a
  170. register the contents of which will be utilized for the operation.
  171.  
  172. There are an unlimited number of memory registers available, as the memory
  173. registers are stored as a virtual array in a disk file. See "Virtual Arrays
  174. in C" by Mark Tichenor, published in the May 1988 issue of Dr. Dobb's Journal.
  175. The downside of this is that some register operations may be slowed due to the
  176. need for disk access; however, a ramdisk may be used by setting an environment
  177. variable named TEMP to the RAMDISK drive. Some operations that use a block
  178. control word are limited to a maximum of 1000 registers (000-999);
  179.  
  180. The financial functions utilize the first ten registers, either to save
  181. financial variables or for scratch registers, so if you want to store data
  182. that won't be overwritten by the financial functions, you will need to use
  183. higher numbered registers. Registers are indexed using standard C array
  184. notation, so the first register is reg[0] the second reg[1], etc. The array
  185. index is retrieved from the stack, so to store the number on top of the stack
  186. in register 0, the command would be 0 STO, with the result that the size of
  187. the stack would be reduced by one. To retrieve this number, the command would
  188. be 0 RCL, and the number that was stored in reg[0] would then be the topmost
  189. number on the stack, which has increased in size by 1.
  190.  
  191. The trigonometric functions assume that angles are expressed in radians. To
  192. convert radians to degrees, multiply by 180/pi; to convert degrees to radians,
  193. multiply by pi/180.
  194.  
  195. The default precision is 20 digits, and the default number of decimal places
  196. for fixed notation is 2. The precision and number of decimal places may be
  197. changed using the prec and fix operations. Naturally, increasing the precision
  198. will slow down calculations. Numbers may be entered using fixed or scientific
  199. notation, eg 123.45678 or 1.2345678E-2 .
  200.  
  201. The following descriptions of the operations implemented include stack diagrams
  202. showing the effect of the operation on the stack. In these diagrams the topmost
  203. element of the stack is on the right, the elements on the stack are numbered to
  204. indicate the order they were placed on the stack, and the result of the
  205. operation is shown.
  206.  
  207. Standard Mathematical functions
  208. -------------------------------
  209.  
  210. +
  211.  
  212.    Replaces the top two numbers on the stack with their sum.
  213.    n1 n2 --- n1+n2
  214.  
  215. -
  216.  
  217.    Replaces the top two numbers on the stack with their difference .
  218.    n1 n2 --- n1-n2
  219.  
  220. *
  221.  
  222.    Replaces the top two numbers on the stack with their product
  223.    n1 n2 --- n1*n2
  224.  
  225. /
  226.  
  227.    Replaces the top two numbers on the stack with the result of dividing the
  228.    second from the top by the topmost.
  229.    n1 n2 --- n1/n2
  230.  
  231. ^
  232.  
  233.    Replaces the top two numbers on the stack with the result of raising the
  234.    second from the top to the power of the topmost.
  235.    n1 n2 --- n1^n2
  236.  
  237. %
  238.  
  239.    Replaces the top two numbers on the stack with the result of multiplying
  240.    the second from the top by the topmost and then dividing by 100.
  241.    n1 n2 --- n1*n2/100.
  242.  
  243.    Note: To add or subtract a percentage to a number, first duplicate the
  244.    number then calculate the percentage and add or subtract it. Thus to add
  245.    15% to a number use the sequence of operations: dup 15%+
  246.  
  247. \
  248.  
  249.    Replaces the top number on the stack with its inverse.
  250.    n1 --- 1/n1
  251.  
  252. ABS
  253.  
  254.    Replaces the top number on the stack with its absolute value.
  255.    n1 --- abs(n1)
  256.  
  257. SQRT
  258.  
  259.    Replaces the top number on the stack with its square root.
  260.    n1 --- sqrt(n1)
  261.  
  262. SQR
  263.  
  264.    Replaces the top number on the stack with its square.
  265.    n1 --- sqr(n1)
  266.  
  267. FACT
  268.  
  269.    Replaces the top number on the stack with its factorial.
  270.    n1 --- n1!
  271.  
  272. INT
  273.  
  274.    Replaces the top number on the stack with its integer part.
  275.    n1 --- int(n1)
  276.  
  277. FRACT
  278.  
  279.    Replaces the top number on the stack with its fractional part.
  280.    n1 --- fract(n1)
  281.  
  282. MOD
  283.  
  284.    Replaces the top two numbers on the stack with the second from the top
  285.    modulo the topmost.
  286.    n1 n2 --- mod(n1,n2)
  287.  
  288. SIN
  289.  
  290.    Replaces the top number on the stack with its sine.
  291.    n1 --- sin(n1)
  292.  
  293. ASIN
  294.  
  295.    Replaces the top number on the stack with its arcsine.
  296.    n1 --- arcsin(n1)
  297.  
  298. COS
  299.  
  300.    Replaces the top number on the stack with its cosine.
  301.    n1 --- cos(n1)
  302.  
  303. ACOS
  304.  
  305.    Replaces the top number on the stack with its arccosine.
  306.    n1 --- arccos(n1)
  307.  
  308. TAN
  309.  
  310.    Replaces the top number on the stack with its tangent.
  311.    n1 --- tan(n1)
  312.  
  313. ATAN
  314.  
  315.    Replaces the top number on the stack with its arctangent.
  316.    n1 --- arctan(n1)
  317.  
  318. LOG
  319.  
  320.    Replaces the top number on the stack with its logarithm to the base 10.
  321.    n1 --- log10(n1)
  322.  
  323. EXP10
  324.  
  325.    Replaces the top number on the stack with 10 raised to the number.
  326.    n1 --- 10^n1
  327.  
  328. LN
  329.  
  330.    Replaces the top number on the stack with its natural logarithm.
  331.    n1 --- ln(n1)
  332.  
  333. EXPE
  334.  
  335.    Replaces the top number on the stack with e raised to the number.
  336.    n1 --- e^n1
  337.  
  338. PI
  339.  
  340.    Adds pi to the stack.
  341.     --- pi
  342.  
  343. E
  344.  
  345.    Adds e to the stack.
  346.     --- e
  347.  
  348. CHS
  349.  
  350.    Changes the sign of the top number on the stack.
  351.    n1 --- -n1
  352.  
  353. SCI
  354.  
  355.    Does not affect the stack. Numbers will be displayed in scientific notation.
  356.  
  357. FIX
  358.  
  359.    The integer part of the number on top of the stack will be used to set
  360.    the number of decimal places and numbers will be displayed as fixed numbers
  361.    based on the precision and number of decimal places set. 0 fix means
  362.    don't display a decimal point or any fractional part of the number.
  363.    n1 ---
  364.  
  365. PREC
  366.  
  367.    The integer part of the number on top of the stack will be used to set the
  368.    precision of succeeding calculations. It will not affect results already
  369.    derived. Numbers will be displayed in fixed or scientific format as
  370.    previously set.
  371.    n1 ---
  372.  
  373.  
  374. Stack and Register Operations
  375. -----------------------------
  376.  
  377. CLST
  378.  
  379.    Clears the stack. Clearing the stack sets the stack pointer to 0, but does
  380.    not reduce the number of stack elements that have been created.
  381.    n1 ... nm ---
  382.  
  383. CLRG
  384.  
  385.    Does not affect the stack. Clears all currently allocated registers to zero.
  386.    Initially there are ten registers. Whenever a register is referenced beyond
  387.    the currently allocated registers, additional virtual registers are
  388.    allocated up to and including the new register. Clearing the registers does
  389.    not reduce the number of registers that have been created.
  390.  
  391. STO
  392.  
  393.    Uses the integer part of the number on top of the stack as an index, and
  394.    stores the nextmost number on the stack in the indexed register. If you
  395.    think of the index number as part of the sto command, the effect is really
  396.    to store the number on top of the stack, but from the point of view of the
  397.    stack, the index has briefly been added to the stack. If STO is directly
  398.    followed by one of the operators + - * / % ^, the operation will be
  399.    performed using the next to last stack entry and the contents of the
  400.    register, e.g. 1 3 STO+ will increment the contents of register 3 by 1,
  401.    10 3 STO/ will divide the contents of register 3 by 10. If a STO operation
  402.    is preceded by the keyword IND, the contents of the indexed register
  403.    will be used as an indirect register address.
  404.    n1 n2 ---
  405.  
  406. RCL
  407.  
  408.    Uses the integer part of the number on top of the stack as an index, and
  409.    recalls the number in the indexed register to the stack. Note that unlike
  410.    storing a number which removes the number from the stack, recalling a number
  411.    leaves it in the register. Has the effect of replacing the number on top of
  412.    the stack by the contents of the register indexed by that number. If a RCL
  413.    operation is preceded by the keyword IND, the contents of the indexed
  414.    register will be used as an indirect register address.
  415.    n1 --- n2
  416.  
  417. DUP
  418.  
  419.    Adds a copy of the number on top of the stack to the stack.
  420.    n1 -- n1 n1
  421.  
  422. DROP
  423.  
  424.    Deletes the number on top of the stack from the stack.
  425.    n1 ---
  426.  
  427. SWAP
  428.  
  429.    Swaps the two numbers on top of the stack.
  430.    n1 n2 --- n2 n1
  431.  
  432. ROT
  433.  
  434.    Rotates the third from the top of the stack to the top of the stack.
  435.    Equivalent to 2 Roll.
  436.    n1 n2 n3 --- n2 n3 n1
  437.  
  438. OVER
  439.  
  440.    Adds a copy of the second number from the top to the stack.
  441.    n1 n2 -- n1 n2 n1
  442.  
  443. PICK
  444.  
  445.    Uses the integer part of the topmost number on the stack to index a
  446.    number on the stack. A copy of the indexed number is added to the stack.
  447.    Like STO, the index number is really part of the pick command, but from the
  448.    point of view of the stack, the index is briefly the top of stack element.
  449.    Indexing for PICK is zero-based, with the top of the stack (index omitted)
  450.    being 0, etc.
  451.  
  452.    Example: 3 PICK
  453.    n1 n2 n3 n4 3 --- n1 n2 n3 n4 n1
  454.  
  455. ROLL
  456.  
  457.    Uses the integer part of the topmost number on the stack to index a
  458.    number on the stack. The indexed number is removed from the stack and moved
  459.    to the top of the stack, Like STO, the index number is really part of the
  460.    pick command, but from the point of view of the stack, the index is briefly
  461.    the top of stack element. Indexing for ROLL is zero-based, with the top of
  462.    the stack (index omitted) being 0, etc.
  463.  
  464.    Example: 3 ROLL
  465.    n1 n2 n3 n4 3 --- n2 n3 n4 n1
  466.  
  467. XCH
  468.  
  469.    Exchanges the number on the stack below the index with the contents of
  470.    the indexed register.
  471.  
  472.    Example: 3 XCH
  473.    n1 3 -- n2
  474.    where n2 was the contents of register 3 and register 3 now contains n1.
  475.  
  476.  
  477. Financial Functions
  478. -------------------
  479.  
  480. The financial functions, N, I, PV, PMT, and FV are those first implemented
  481. in the HP-92, as modified for the HP-41 in the PPC ROM. A full explanation
  482. is provided in the PPC ROM User's Manual (1981), from which the algorithm was
  483. derived and the examples taken, as well as in many standard references.
  484.  
  485. The rule for financial calculations using these functions is that money paid
  486. out is considered negative and money received is considered positive in sign.
  487. There are five financial variables. N (number of periods), I (interest rate),
  488. PV (present value), PMT (payment), and FV (future value), and given any three
  489. of them, the other two can be calculated. This calculator includes two
  490. additional parameters, CF, compounding frequency (number of times the interest
  491. rate is compounded during the period for which the interest rate is I%), and
  492. PF, payment frequency (number of payment periods during the period for which
  493. the interest rate is I%). These additional parameters simplify the solution of
  494. some complex financial problems. In addition, there are toggles for beginning
  495. of period/end of period payment and continuous/discrete compounding. The
  496. financial functions either store a number in a register (N - 1, I - 2, PV - 3,
  497. PMT - 4, FV - 5) or calculate that variable based on the other numbers entered,
  498. depending on whether the data entry flag is set. This flag is automatically
  499. set whenever a number is entered or calculated and turned off when a financial
  500. operation is performed. See the examples for details.
  501.  
  502. N
  503.  
  504. Either stores the number of periods in register 1, or calculates N based on
  505. two other values.
  506. n1 ---
  507.  --- n1
  508.  
  509. I
  510.  
  511. Either stores the interest rate in register 2, or calculates I.
  512. n1 ---
  513.  --- n1
  514.  
  515. PV
  516.  
  517. Either stores the present value in register 3, or calculates PV.
  518. n1 ---
  519.  --- n1
  520.  
  521. PMT
  522.  
  523. Either stores the payment in register 4, or calculates PMT.
  524. n1 ---
  525.  --- n1
  526.  
  527. FV
  528.  
  529. Either stores the future value in register 5, or calculates FV.
  530. n1 ---
  531.  --- n1
  532.  
  533. CF
  534.  
  535. Sets the compounding frequency.
  536. n1 --
  537.  
  538. PF
  539.  
  540. Sets the payment frequency.
  541. n1 --
  542.  
  543. BE
  544.  
  545. Toggles the beginning/end payment flag.
  546. Does not affect the stack.
  547.  
  548. CD
  549.  
  550. Toggles the continuous/discrete payment flag.
  551. Does not affect the stack.
  552.  
  553. CLRF
  554.  
  555. Clears registers 1 through 5 used for financial variables,
  556. sets CF=PF=1, sets BE to E and CD to D.
  557.  
  558. Examples
  559.  
  560. Monthly payment. A couple purchases a $50,000 house, borrowing $40,000
  561. at 8.5% for 30 years less one month. What is their monthly payment.
  562.  
  563.         clrf 40,000 pv 8.5 12/ i 30 12* 1- n pmt
  564.         result is PMT = $307.75
  565.  
  566. Internal rate of return. The couple above then sold their house 18 months
  567. later, netting $25,000. At what annual interest rate would they have had to
  568. invest their original $10,000 and $307.75 monthly payments to obtain $25,000.
  569.  
  570.         clrf 18 n 25,000 fv -10,000 pv -307.75 pmt i 12*
  571.         result is I = 38.51%
  572.  
  573. Simple interest. Find the annual simple interest rate (%i) for an $800 loan
  574. to be repaid at the end of one year with a single payment of $896.
  575.  
  576.         clrf 1 n -800 pv 896 fv i
  577.         result is APR = 12.0%
  578.  
  579. Compound interest. Find the future value of an $800 loan after one year at a
  580. nominal rate of 12% compounded monthly. No payments are specified, so the
  581. payment frequency is set equal to the compounding frequency.
  582.  
  583.         clrf 12 n 12 dup cf pf 12 i -800 pv fv
  584.         result is FV = 901.46
  585.  
  586. Periodic payment. Find the monthly end of period payment required to fully
  587. amortize the loan in the preceding example. A fully amortized loan has a future
  588. value of zero. Use data retained from preceding example.
  589.  
  590.         0 fv pmt
  591.         result is PMT = $71.08
  592.  
  593. Conventional mortgage. Find the number of monthly payments necessary to
  594. fully amortize a loan of $100,000 at a nominal rate of 13.25% compounded
  595. monthly, if end of period payments of $1,125.75 are made.
  596.  
  597.         clrf 12 dup cf pf 13.25 i 100,000 pv -1,125.75 pmt n
  598.         result is N = 360.10
  599.  
  600. Final payment. Using the same data as in the preceding example, find the
  601. amount of the final payment if n is changed to 360. The final payment is
  602. equal to the regular payment plus any balance remaining (FV) at the end of
  603. the last period.
  604.  
  605.         360.0 n fv 4 rcl+
  606.         result is final PMT = $1,234.62
  607.  
  608. Balloon payment. On long term loans, small changes in the periodic payments
  609. can result in large changes in the future value. If the monthly payment in
  610. the preceding example is rounded down to $1,125 what is the additional balloon
  611. payment due with the final payment?
  612.  
  613.         -1,125 pmt fv
  614.         result is balloon payment of $3,579.99
  615.  
  616. Canadian mortgage. Find the monthly end-of-period payment necessary to fully
  617. amortize a 25 year $85,000 loan at 11% compounded semiannually.
  618.  
  619.         clrf 2 cf 12 pf 25 12* n 11 i 85,000 pv pmt
  620.         result is PMT=818.15
  621.  
  622. European mortgage. The "effective annual rate" (EAR) is used in some European
  623. countries instead of the nominal annual rate commonly used in the US and
  624. Canada. For a 30 year $90,000 mortgage at 14% EAR compute the monthly end-of-
  625. period payments, noting that when using an EAR, the compounding frequency is
  626. set to 1.
  627.  
  628.         clrf 12 pf 360 n 14 i 90,000 pv pmt
  629.         result is PMT=$1,007.88
  630.  
  631. Bi-weekly savings. Compute the future value of bi-weekly savings of $100 for
  632. three years at a nominal annual rate of 5.5% compounded daily. Note that
  633. it is necessary to toggle the BE flag to beginning of period.
  634.  
  635.         clrf be 365 cf 26 dup pf 3* n 5.5 i -100 pmt fv
  636.         result is FV=$8,489.32
  637.  
  638. Present value of an annuity. What is the present value of $500 to be received
  639. at the beginning of each quarter over a 10 year period if money is being
  640. discounted at a 10% nominal annual rate compounded monthly. Note that it
  641. is necessary to toggle the BE flag.
  642.  
  643.         clrf be 12 cf 4 dup pf 10* n 10 i 500 pmt pv
  644.         result is PV=$12,822.64
  645.  
  646. Balloon payment. Compute the monthly end-of-period payment on a 3 year
  647. $20,000 loan at 15% nominal annual rate compounded monthly, with a $10,000
  648. balloon payment due at the end of the 37th period. Note that the balloon
  649. payment must be discounted one period to make it coincide with the last
  650. regular payment.
  651.  
  652.         clrf 12 dup dup cf pf 3* n 15 i 20,000 pv pmt
  653.         at this point the effective monthly interest rate as a decimal is in
  654.         register 6; throw away the number on the stack (monthly pmt without
  655.         the balloon) and continue as follows:  drop -10,000 6 rcl 1+ / fv pmt
  656.         result is PMT=474.39
  657.  
  658. Effective rate using a 365/360 basis. Compute the effective annual rate (%APR)
  659. for a nominal annual rate of 12% compounded on a 365/350 basis.
  660.  
  661.         clrf 3 fix 365 dup n cf 360 pf 12 i -100 pv fv 3 rcl +
  662.         result is APR=12.935%
  663.  
  664. Mortgage with points. What is the true APR of a 30 year, $75,000 loan at a
  665. nominal rate of 13.25% compounded monthly, with monthly end-of-period payments
  666. of $844.33 if 3 points are charged? The PV must be reduced by the dollar value
  667. of the points  to establish an effective PV. Because the payments remain the same,
  668. the true APR will be higher than the nominal rate.
  669.  
  670.         clrf 12 dup dup cf pf 30* n 75,000 dup 3% - pv -844.33 pmt i
  671.         result is APR=13.69%
  672.  
  673. Equivalent payments. Find the equivalent monthly payment required to amortize
  674. a 20 year $40,000 loan at 10.5% nominal annual rate compounded monthly, with
  675. ten annual payments of $5,029.71 remaining. Compute the PV of the remaining
  676. annual payments then change n and PF to a monthly basis and compute the equivalent
  677. monthly payment.
  678.  
  679.         clrf 12 cf 10 n 10.5 i -5,029.71 pmt pv
  680.         PV of remaining payments is $29,595.88
  681.         12 dup pf 10* n pmt
  682.         result is monthly PMT=$399.35
  683.  
  684. Perpetuity with continuous compounding. If you can purchase a single payment
  685. annuity with an initial investment of $60,000 that will be invested at a 15%
  686. nominal annual rate compounded continuously, what is the maximum monthly
  687. return you can receive without reducing the principal. If the interest rate
  688. is constant and the principal is not disturbed the payments can go on
  689. indefinitely. Note that the term n of a perpetuity is immaterial and can
  690. be set to any non-zero value.
  691.  
  692.         clrf cd 12 dup pf n 15 i 60,000 dup fv -1* pv pmt
  693.         result is PMT=$754.71
  694.  
  695.  
  696. Calendar and Time Functions
  697. ---------------------------
  698.  
  699. The calendar functions JDN and Date are inverses. JDN computes the Julian Day
  700. Number for a given calendar date and date converts a JDN to a calendar date.
  701. The valid range for dates is from March 1 of the year 0 CE (Common Era, also
  702. known as AD) to sometime in the far future. All dates are assumed to follow
  703. the Gregorian calendar, which was originally devised in 1582, adopted in 1752
  704. by the British Empire, including the then American colonies, and as late as
  705. 1927 for Turkey. It is possible to use a somewhat more complicated algorithm to
  706. allow for dates in either the Gregorian or the Julian calendars, and including
  707. dates BCE (Before the Common Era, also known as BC) but this program does not
  708. do so at present.
  709.  
  710. The Julian Day Number should not be confused with the Julian Calendar. The
  711. Julian Day Number is the number of whole days that have elapsed since a certain
  712. reference time in the past. The JDN is widely used in astronomy and elsewhere
  713. in calculations involving dates. The reference time is January 1, 4713 BCE,
  714. Julian Calendar, at noon.
  715.  
  716. It should be noted that the day of the week corresponding to a given date can
  717. be easily calculated given the JDN. The day of the week is (JDN + 1) MOD 7,
  718. where 0 = Sunday, 1 = Monday, etc.
  719.  
  720. JDN
  721.  
  722. Converts a calendar date in the form YYYY.MMDD to the corresponding JDN.
  723. n1 --- n1
  724.  
  725. DOW
  726.  
  727. Displays the day of the week corresponding to the julian day number on the
  728. stack.
  729. n1 ---
  730.  
  731. DATE
  732.  
  733. Converts a JDN to a calendar date in the form YYYY.MMDD
  734. n1 --- n2
  735.  
  736.  
  737. Examples
  738.  
  739. The attack on Pearl Harbor occured on December 7, 1941. What day of the week
  740. was it?
  741.  
  742.         1941.1207 jdn dow
  743.         result is Sunday
  744.  
  745. What day of the year is July 4, 1993?
  746.  
  747.         1993.0704 jdn 1992.1231 jdn -
  748.         result is  July 4, 1993 is the 185th day of the year
  749.  
  750. What day is 90 days after July 4, 1993?
  751.  
  752.         4 fix 1993.0704 jdn 90+ date
  753.         result is 1993.1002 or October 2
  754.  
  755.  
  756. The time functions HMS and HRS allow converting between times expressed
  757. as decimal numbers and times expressed as hours, minutes, seconds. The time
  758. functions have precision only to the hundredth of a second.
  759.  
  760. HMS
  761.  
  762. Converts time expressed as a decimal number H.DDDDDD to H.MMSSCC, where H is
  763. hours, DDDDDD is some fraction of an hour, MM is minutes, SS is seconds, and
  764. CC is hundredths of a second. Result is rounded to CC.
  765. H.DDDDDDDD --- H.MMSSCC
  766.  
  767. HRS
  768.  
  769. Converts a time expressed as H.MMSSCC to H.DDDDDD
  770. H.MMSSCC --- H.DDDDDD
  771.  
  772.  
  773. Support for Hexadecimal, Octal, and Binary Integers
  774. ---------------------------------------------------
  775.  
  776. Numbers may be displayed in hexadecimal, octal, or binary by using the HEX,
  777. OCT, or BIN keywords. Only the integer parts of the numbers will be used.
  778. Hexadecimal, octal, and binary integers are entered using the prefix 0x, 0o,
  779. or 0b, respectively, eg 0xABC, 0o5703 or 0b11001. The base conversion code uses
  780. long doubles (which have 64 bit mantissas) as an intermediate form, so the base
  781. conversions are limited to binary integers of 64 or fewer bits (16 hexadecimal
  782. digits).
  783.  
  784.  
  785. Miscellaneous Operations
  786. ------------------------
  787.  
  788. CLS
  789.  
  790. Clears the screen. Does not affect the stack.
  791.  
  792. VIEW
  793.  
  794. Displays selected registers based on the block control word bbb.eeeii
  795. where bbb is the first register to view, eee is the last register to view,
  796. and ii is the increment. The block control word is retrieved from the register
  797. on top of the stack.
  798. r ---
  799.  
  800. SHOWS
  801.  
  802. Displays the stack from top to bottom. the stack is not affected.
  803.  
  804. STOM
  805.  
  806. Stores the contents of the stack based on the block control word. The block
  807. control word is retrieved from the register on top of the stack. Starts
  808. with the top element on the stack not counting the block control word pointer
  809. stores it in the last register in the block and decrements until done. At the
  810. end, numbers will be stored in same order they were entered on stack.
  811. n1 n2 ... nm r ---
  812.  
  813. RCLM
  814.  
  815. Recalls the contents of a block of registers to the stack based on the block
  816. control word. The block control word is retrieved from the register on top of
  817. the stack. Starts with the first register in the block and increments to
  818. restore the stack in the same order it was originally.
  819. r --- n1 n2 ... nm
  820.  
  821. QUIT or EXIT
  822. terminates the program
  823.  
  824.  
  825. Programming
  826. -----------
  827.  
  828. Programs may be written using any editor and then loaded and executed. Pressing
  829. F2 will invoke the editor defined by your environment variable EDIT. Several
  830. sample programs are provided, including a mortgage amortization schedule, a
  831. linear regression program, a root finder, and a conversions program. A program
  832. may be automatically loaded and run by running papc with the program name as
  833. an argument. Execution will begin with the first statement in the program. To
  834. save the output of a program in a file, use redirection. For example, to use
  835. the amortization program to generate and save an amortization schedule, enter
  836.  
  837.          papc mortgage.prg > mortage.prn <CR>
  838.  
  839. at the DOS command line.
  840.  
  841. Be sure to have a QUIT instruction in the program if you are redirecting your
  842. output, otherwise when the program is finished, PAPC will go back into
  843. interactive mode and you won't know it. Unless stated otherwise, programming
  844. operators can not be used interactively, but only within programs. A semicolon
  845. is used to begin a comment. Once a semicolon has been parsed, the rest of the
  846. line is skipped. For debugging, a single-step option can be toggled by F10.
  847. While single step is enabled, the prompt will be $ instead of >, and after each
  848. program line is executed, PAPC will pause. Press any key to continue, except
  849. lower-case 'q', which will return you to interactive mode, lower-case 'i'
  850. which will put you in interactive (stopped) mode, lower-case 'r' which will
  851. turn off single stepping, or lower-case 's' which will do a stack dump before
  852. continuing.
  853.  
  854. LOAD
  855.  
  856. Loads the program(s) in a file. If you need to use a path in the filename,
  857. enclose the name in quotes, eg load "c:\xyz\progname". The filename may be any
  858. legal DOS filename, although I have used a filetype of .PRG in the samples. A
  859. file may contain multiple programs. There are no particular formatting
  860. requirements, but putting one operation on a line may be helpful for debugging.
  861. A program is terminated by an END statement. If you don't include an END
  862. statement, one will be appended when the file is loaded. The load command may
  863. be executed in interactive mode. Load statements in a program file will be
  864. executed immediately, as shown in the sample LOADALL program. Once a program
  865. has been loaded, it may be executed by saying XEQ progname where progname is
  866. the label of the entrypoint, or just by entering the name of the entrypoint.
  867.  
  868. Example: LOAD xyz
  869.  
  870. CAT
  871.  
  872. Displays a catalog of all labels that have been loaded. May be executed in
  873. interactive mode. CAT in a program file will be executed immediately.
  874.  
  875. CLP
  876.  
  877. Clears a program and deletes all labels that are in the program from the
  878. catalog. May be executed in interactive mode. CLP statements in a program file
  879. will be executed immediately.
  880.  
  881. Example: CLP xyz
  882.  
  883. CLCAT
  884.  
  885. Clears all programs from the catalog. May only be executed in interactive mode.
  886.  
  887. LBL
  888.  
  889. Defines a label and enters it in the catalog.
  890.  
  891. Examples: LBL a, LBL ThisIsAVeryLongLabel, LBL 01
  892.  
  893. END
  894.  
  895. Defines the end of a program, and functions like a RTN.
  896.  
  897. PUTS
  898.  
  899. Puts a string to the console
  900.  
  901. Example: PUTS "This is a string to put to the console\n". Note that unlike
  902.          the C puts (), a newline is not automatically appended. Use \n for
  903.          a newline.
  904.  
  905. PROMPT
  906.  
  907. Puts a string to the console and then gets a line of input which is parsed and
  908. executed. If a NULL line is entered (ie, just a <CR>) the next instruction is
  909. executed, otherwise the next line is skipped. The reason for this is to
  910. provide a mechanism to escape from a data entry loop.
  911.  
  912. Example: LBL DATAENTRY
  913.          PROMPT "Enter a number: "
  914.          GTO NEXT  ; only if a number wasn't entered
  915.          .  ; data entry processing
  916.          .
  917.          .
  918.          GTO DATAENTRY
  919.          LBL NEXT ; continue
  920.  
  921. XEQ
  922.  
  923. Calls a program or subroutine, the next instruction in the calling program
  924. will be executed when a RTN or END instruction is executed. May be used in
  925. interactive mode to execute a program. Ten levels of subroutines are allowed.
  926. XEQ is not required for a previously defined label (backward reference), which
  927. will be resolved without it, but is necessary for a label that has not yet been
  928. defined (forward reference).
  929.  
  930. Example: (interactive) XEQ aprogram or aprogram
  931.          (program) ... XEQ subxyz ...
  932.  
  933. GTO
  934.  
  935. Transfers control to a LBL
  936.  
  937. Example: GTO xyz
  938.  
  939. RTN
  940.  
  941. Returns from a subroutine call, or to interactive mode if the program was
  942. invoked from the PAPC command line.
  943.  
  944. JMP
  945.  
  946. JMP takes the number on top of the stack, or the contents of a register if IND
  947. is used, adds that to the program instruction counter and then transfers to
  948. that instruction. JMP may be used to implement a simple case mechanism.
  949.  
  950. Example:
  951.  
  952.    LBL test2
  953.    PROMPT "Enter a number 1, 2, or 3, or CR to exit: "
  954.    ; next line executed if just a CR is entered
  955.    GTO done
  956.    ; here if a number was entered
  957.    1 <
  958.    GTO error
  959.    3 >
  960.    GTO error
  961.    JMP
  962.    GTO one
  963.    GTO two
  964.    GTO three
  965.  
  966. STOP
  967.  
  968. Returns immediately to interactive mode. The program can be resumed where it
  969. left off using RUN. The prompt will be  while you are in stopped mode.
  970.  
  971. RUN
  972.  
  973. Resume the program where it left off. Can only be used from interactive mode.
  974.  
  975. PAUSE
  976.  
  977. Pauses program and waits for a keystroke to continue. Press any key to continue,
  978. except lower-case 'q', which will return you to interactive mode, lower-case
  979. 'i' which will put you in interactive (stopped) mode, lower-case 'r' which will
  980. turn off single stepping, or lower-case 's' which will do a stack dump before
  981. continuing.
  982.  
  983. ISG
  984.  
  985. Increment and skip if greater. Uses a block control word bbb.eeeii to control
  986. program flow. The block control word is retrieved from the register on top of
  987. the stack. ii is added to bbb, if the result is greater than eee, the next
  988. instruction is skipped. The updated block is stored back in the same register.
  989.  
  990. DSE
  991.  
  992. Decrement and skip if less than or equal. Uses a block control word bbb.eeeii
  993. to control program flow. The block control word is retrieved from the register
  994. on top of the stack. ii is added to bbb, if the result is equal to or less than
  995. than eee, the next instruction is skipped. The updated block is stored back in
  996. the same register.
  997.  
  998. PUTX
  999.  
  1000. Puts the second number on the stack to the console using the topmost number as
  1001. a field width. The topmost number is dropped. A field width of 0 indicates no
  1002. fixed field width (like interactive mode).
  1003.  
  1004. ==
  1005.  
  1006. Compares the second number on the stack to the number on top of the stack,
  1007. which is dropped, If the numbers are equal, the next instruction is executed,
  1008. otherwise it is skipped (DO IF TRUE rule).
  1009.  
  1010. Example: ... 3 == ..., perform next instruction if the next to the topmost
  1011. number on the stack is equal to 3, the comparison number is dropped.
  1012.  
  1013. !=
  1014.  
  1015. Compares the second number on the stack to the number on top of the stack,
  1016. which is dropped, If the numbers are not equal, the next instruction is
  1017. executed, otherwise it is skipped (DO IF TRUE rule).
  1018.  
  1019. Example: ... 3 != ..., perform next instruction if the next to the topmost
  1020. number on the stack is not equal to 3, the comparison number is dropped.
  1021.  
  1022. >
  1023.  
  1024. Compares the second number on the stack to the number on top of the stack,
  1025. which is dropped, If the number is > than the comparison number, the next
  1026. instruction is executed, otherwise it is skipped (DO IF TRUE rule).
  1027.  
  1028. Example: ... 3 > ..., perform next instruction if the next to the topmost
  1029. number on the stack is > 3, the comparison number is dropped.
  1030.  
  1031. >=
  1032.  
  1033. Compares the second number on the stack to the number on top of the stack,
  1034. which is dropped, If the number is >= than the comparison number, the next
  1035. instruction is executed, otherwise it is skipped (DO IF TRUE rule).
  1036.  
  1037. Example: ... 3 >= ..., perform next instruction if the next to the topmost number on
  1038. the stack is >= 3, the comparison number is dropped.
  1039.  
  1040. <
  1041.  
  1042. Compares the second number on the stack to the number on top of the stack,
  1043. which is dropped, If the number is < than the comparison number, the next
  1044. instruction is executed, otherwise it is skipped (DO IF TRUE rule).
  1045.  
  1046. Example: ... 3 < ..., perform next instruction if the next to the topmost number on
  1047. the stack is < 3, the comparison number is dropped.
  1048.  
  1049. <=
  1050.  
  1051. Compares the second number on the stack to the number on top of the stack,
  1052. which is dropped, If the number is <= than the comparison number, the next
  1053. instruction is executed, otherwise it is skipped (DO IF TRUE rule).
  1054.  
  1055. Example: ... 3 <= ..., perform next instruction if the next to the topmost number on
  1056. the stack is <= 3, the comparison number is dropped.
  1057.  
  1058. Flag operations
  1059.  
  1060. There are ten user flags 0 through 9 that can be used in programs. Flags
  1061. are indexed by a number on the stack, or indirectly by the contents of a
  1062. register number.
  1063.  
  1064. FS
  1065.  
  1066. Set a flag.
  1067.  
  1068. Examples: 3 FS, 3 IND FS
  1069.  
  1070. FC
  1071.  
  1072. Clear a flag.
  1073.  
  1074. FS?
  1075.  
  1076. Test whether a flag is set, if so execute the next instruction, otherwise
  1077. skip over it (DO IF TRUE).
  1078.  
  1079. FC?
  1080.  
  1081. Test whether a flag is clear, if so execute the next instruction, otherwise
  1082. skip over it (DO IF TRUE).
  1083.  
  1084. FS?C
  1085.  
  1086. Test whether a flag is set and then clear it, if the flag was set execute
  1087. the next instruction, otherwise skip over it (DO IF TRUE)
  1088.  
  1089. FC?C
  1090.  
  1091. Test whether a flag is clear and then clear it, if the flag was clear execute
  1092. the next instruction, otherwise skip over it (DO IF TRUE)
  1093.  
  1094. -----------------------------------------------------------------------------
  1095.  
  1096. This program (The Programmable Arbitrary Precision RPN Calculator) is released
  1097. as shareware, if you like it and plan to use it regularly, please send $25 to:
  1098.  
  1099.                      S. Jason Olasky
  1100.                      874 New Mark Esplanade
  1101.                      Rockville, MD 20850
  1102.  
  1103. You will receive a copy, registered to you, by return mail. A license to the
  1104. source code is available for an additional $25. If you want the source code,
  1105. please send me a statement that the source code is only for your own use and
  1106. that you do not intend to resell the program or modified versions of it without
  1107. my consent.
  1108.  
  1109. THE PROGRAMMABLE ARBITRARY PRECISION RPN CALCULATOR AND ALL ACCOMPANYING
  1110. MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK
  1111. OF USING THE PROGRAMMABLE ARBITRARY PRECISION RPN CALCULATOR IS ASSUMED BY YOU.
  1112.  
  1113. S. Jason Olasky makes no warranty of any kind, express or implied, including
  1114. but not limited to any warranties of merchantability and fitness for a
  1115. particular purpose.
  1116.  
  1117. IN NO EVENT WILL S. JASON OLASKY BE LIABLE FOR ANY DAMAGES WHATSOEVER
  1118. (INCLUDING BUT NOT LIMITED TO DAMAGES FOR LOSS OF BUSINESS PROFITS, LOSS OF
  1119. SAVINGS, BUSINESS INTERRUPTION, AND THE LIKE) ARISING OUT OF YOUR USE OR
  1120. INABILITY TO USE THE PROGRAM. BY USING THE PROGRAMMABLE ARBITRARY PRECISION
  1121. RPN CALCULATOR, YOU AGREE TO THE ABOVE LIMITATIONS.
  1122.  
  1123. Portions of this code were derived from the following sources:
  1124.  
  1125. Bigcalc by Judson D. McClendon
  1126. Parser by Lloyd Zusman
  1127. Editstr by Bob Bybee
  1128. Varray by Mark Tichenor
  1129. Exec by Thomas Wagner
  1130. Llist by Bob DuBose
  1131.  
  1132. Notifications of bugs, suggested improvements, or comments in general are welcome.
  1133.